package com.czf.CurriculumVitae.db;

import com.czf.CurriculumVitae.bean.Admin;
import com.czf.CurriculumVitae.util.DBUtil;

import java.sql.*;

/**
 * @author chen
 * @Description:
 * @date 2021/3/25 11:12
 */
public class RegisterDaoImp implements BaseDao<Admin> {
    private static final String SQL_INSERT = "insert into kkb_login(id,username,password) values(?,?,?)";

    @Override
    public int insert(Admin admin) {

        Connection conn = DBUtil.getConn();
        PreparedStatement state = null;
        try {
            state = conn.prepareStatement(SQL_INSERT, Statement.RETURN_GENERATED_KEYS);
            state.setString(1, admin.getId());
            state.setString(2, admin.getUsername());
            state.setString(3, admin.getPassword());

            //执行
            int row = state.executeUpdate();
            //返回结果
            return row>0?row:-1;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            DBUtil.close(conn,state,null);
        }

        return -1;
    }

    @Override
    public Admin findByUserId(String userId) {
        return null;
    }

}
